$(function(){
    cssresize_st();
    $(window).resize(function(){cssresize_st()});
    $.feelywiki.init({
        "titleElem" : "#h-title",
        "wikiPrefix" : "/wiki/",
        "redirectParam" : "redirectfrom"
    });
});
function showsource(){
    $("#content-c").fadeOut(300);
    $("#content-s").fadeIn(300);
}
function hidesource(){
    $("#content-c").fadeIn(300);
    $("#content-s").fadeOut(300);
}
function closewrap(){
    $("#content-wrap").fadeOut(500);
}
function showDetail(hisId){
    cssresize_st();
    $.getJSON("/history/gethistory.json", {
        "id" : hisId
    }, function(data){
        if(data.result=="error"){
            alert("无法获取信息："+data.info);
        }else{
            $("#h-source").val(data.content);
            $("#h-reason").html(data.reason);
            $("#h-edittime").html(data.edit_time);
            $("#h-title").html(data.title);
            $("#h-c").html($.feelywiki.start(data.content));
            getUsernameAndAvatar(data.author);
        }
    });
    $("#content-wrap").fadeIn(500);
}
function getUsernameAndAvatar(uid){
    $.get("/getavatar.json", {"uid": uid}, function(data){
        $("#h-avatar").attr("src", data);
    });
    $.get("/getusername.json", {"uid": uid}, function(data){
        $("#h-uname").html(data);
    });
}
function cssresize_st(){
    var w=window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    var h=window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
    $("#content-wrap").css({
        "left":(w - parseInt($("#content-wrap").css("width")))/2 +"px",
        "top": (h - parseInt($("#content-wrap").css("height")))/2 +"px"
    });
}